package com.woniu.microchargeserver.common.mapper;

import com.woniu.microcommonsserver.entity.ChargedItemsInfoEntity;
import org.apache.ibatis.annotations.*;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**收费项目的mapper
 * @author: hejie
 * @date: 2021/1/23 8:04
 * @description:
 */
@Mapper
public interface ChargedItemsMapper {

    /**
     * 删除 一个收费项目
     * @author hejie
     * @param id
     * @return
     */
    @Delete("delete from charged_items_info where id = #{id}")
    void deleteChargedItems(@Param("id") Long id);

    /**
     * 分页查询
     * @param chargedItemsInfo
     * @return
     */
    List<ChargedItemsInfoEntity> findAllByParams(@Param("a") ChargedItemsInfoEntity chargedItemsInfo,
                                                 @Param("chargeCodeOrName") String chargeCodeOrName,
                                                 @Param("col") String colume,
                                                 @Param("order") String order);

    /**新增一个 收费项目
     * @author hejie
     * @param chargedItemsInfo
     * @return
     */
    @Options(
            useGeneratedKeys = true,
            keyProperty = "a.id"
    )
    @Insert("insert into charged_items_info " +
            "(charge_code,charge_name, charge_way, charge_type, billi_unit_price, cycle_units, bill_cycles, bill_accuracy, choice_method," +
            "bill_method, bill_formula, late_fee_rate, overdue_pay_dayst)" +
            " values(#{a.chargeCode},#{a.chargeName},#{a.chargeWay},#{a.chargeType},#{a.billiUnitPrice},#{a.cycleUnits},1," +
            "#{a.billAccuracy},#{a.choiceMethod},#{a.billMethod},#{a.billFormula},#{a.lateFeeRate},#{a.overduePayDayst})" )
    void saveChargedItems(@Param("a") ChargedItemsInfoEntity chargedItemsInfo);

    /**
     * 修改 一个收费项目
     * @author hejie
     * @param chargedItemsInfo
     * @return
     */
    void updateChargedItems(@Param("a") ChargedItemsInfoEntity chargedItemsInfo);

    /**
     * 查询所有的“收费项目”
     * @author hejie
     * @return
     */
    @ResultType(ChargedItemsInfoEntity.class)
    @Select("select id,charge_name as chargeName from charged_items_info")
    List<ChargedItemsInfoEntity> findAllChargedItems();

    /**根据id：查询收费项目的 “周期方式”和周期数：为了“房间、收费中间表中的结束时间的计算”
     *  charge_way           tinyint comment '收费方式。1--周期性，2--临时性',
     * cycle_units          tinyint comment '周期单位。1-月，2-日',
     bill_cycles 周期数
     * @param id
     * @return
     */
    @ResultType(ChargedItemsInfoEntity.class)
    @Select("select id,charge_way as chargeWay,cycle_units as cycleUnits,bill_cycles as billCycles,billi_unit_price billiUnitPrice " +
            " from charged_items_info where id=#{id}")
    ChargedItemsInfoEntity findById( Long id);
}
